package com.yujiahao;

import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

/**
 * @Description :
 * @Author:yujiahao
 * @Date: 2023/6/23 23:10
 * @Version: 1.0
 */
public class Util {


    /**
     * 获取生肖的key、普通计数
     *
     * @param value
     * @return
     */
    public static int getShenKey(String value) {

        //生肖
        Map<Integer, String> zodiac = new HashMap<>();
        zodiac.put(1, "子鼠");
        zodiac.put(2, "丑牛");
        zodiac.put(3, "寅虎");
        zodiac.put(4, "卯兔");
        zodiac.put(5, "辰龙");
        zodiac.put(6, "巳蛇");
        zodiac.put(7, "午马");
        zodiac.put(8, "未羊");
        zodiac.put(9, "申猴");
        zodiac.put(10, "酉鸡");
        zodiac.put(11, "戌狗");
        zodiac.put(12, "亥猪");

        int targetKey = 0;
        //获取到保存所有键对象的子集合
        Set<Integer> keySet = zodiac.keySet();
        //用迭代器进行遍历
        Iterator<Integer> iterator = keySet.iterator();
        while (iterator.hasNext()) {
            Integer key = iterator.next();
            if (zodiac.get(key) .equals(value) ) {
                targetKey = key.intValue();
            }
        }
        return targetKey;
    }

    /**
     * 获取所属年的生肖、普通计数
     * @param key
     * @return
     */
    public static String getShenVelues(int key) {

        //生肖
        Map<Integer, String> zodiac = new HashMap<>();
        zodiac.put(1,  "子鼠");
        zodiac.put(2,  "丑牛");
        zodiac.put(3,  "寅虎");
        zodiac.put(4,  "卯兔");
        zodiac.put(5,  "辰龙");
        zodiac.put(6,  "巳蛇");
        zodiac.put(7,  "午马");
        zodiac.put(8,  "未羊");
        zodiac.put(9,  "申猴");
        zodiac.put(10, "酉鸡");
        zodiac.put(11, "戌狗");
        zodiac.put(12, "亥猪");

        return zodiac.get(key).toString();

    }

    /**
     * 获取天干和地址 两个的方法
     * @param qian
     * @param kun
     * @return
     */
    public static String getChineseEra(Integer qian, Integer kun) {

        //将天干和地址分别封装在集合里面

        Map<Integer, String> tianGan = new HashMap<>();
        tianGan.put(4, "甲");
        tianGan.put(5, "乙");
        tianGan.put(6, "丙");
        tianGan.put(7, "丁");
        tianGan.put(8, "戊");
        tianGan.put(9, "己");
        tianGan.put(0, "庚");
        tianGan.put(1, "辛");
        tianGan.put(2, "壬");
        tianGan.put(3, "癸");


        Map<Integer, String> diZhi = new HashMap<>();
        diZhi.put(4, "子");
        diZhi.put(5, "丑");
        diZhi.put(6, "寅");
        diZhi.put(7, "卯");
        diZhi.put(8, "辰");
        diZhi.put(9, "巳");
        diZhi.put(10, "午");
        diZhi.put(11, "未");
        diZhi.put(0, "申");
        diZhi.put(1, "酉");
        diZhi.put(2, "戌");
        diZhi.put(3, "亥");

        //生肖
        Map<Integer, String> zodiac  = new HashMap<>();
        zodiac.put(4, "鼠");
        zodiac.put(5, "牛");
        zodiac.put(6, "虎");
        zodiac.put(7, "兔");
        zodiac.put(8, "龙");
        zodiac.put(9, "蛇");
        zodiac.put(10,"马");
        zodiac.put(11,"羊");
        zodiac.put(0, "猴");
        zodiac.put(1, "鸡");
        zodiac.put(2, "狗");
        zodiac.put(3, "猪");

        return    diZhi.get(kun) + zodiac.get(kun)+ "（农历" + tianGan.get(qian) + diZhi.get(kun) + "年）";

    }
    /**
     * 将用户输入的生肖转换为地支+生肖
     * @param shengxiao
     * @return
     */
    public static String changeVelues (String shengxiao){

        StringBuilder stringBuilder = new StringBuilder();
        switch(shengxiao){

            case "鼠": stringBuilder.append("子鼠");break;
            case "牛": stringBuilder.append("丑牛");break;
            case "虎": stringBuilder.append("寅虎");break;
            case "兔": stringBuilder.append("卯兔");break;
            case "龙": stringBuilder.append("辰龙");break;
            case "蛇": stringBuilder.append("巳蛇");break;
            case "马": stringBuilder.append("午马");break;
            case "羊": stringBuilder.append("未羊");break;
            case "猴": stringBuilder.append("申猴");break;
            case "鸡": stringBuilder.append("酉鸡");break;
            case "狗": stringBuilder.append("戌狗");break;
            case "猪": stringBuilder.append("亥猪");break;

    }
    return stringBuilder.toString();
}
    //快排算法
    public static void quick(int[] arr, int begin, int end) {

        if (begin >= end) {
            return;
        }
        int key = arr[begin];
        int indext = begin;
        for (int i = begin; i < end; i++) {
            if (arr[i] < key) {

                indext++;
                int temp = arr[i];
                arr[i] = arr[indext];
                arr[indext] = temp;

            }

        }
        arr[begin] = arr[indext];
        arr[indext] = key;

        quick(arr, begin, indext);
        quick(arr, indext + 1, end);

    }

}
